﻿using System.Reflection.Metadata.Ecma335;

namespace ConsoleApplication3delegate
{
    class DepositCard
    {
        public int amount;
        public void Display()
        {
            Console.WriteLine("储蓄卡余额为：{0}", amount);
        }
        public void Account(int balance, int payday)
        {
            amount += balance;
            Console.WriteLine("今天是本月的{0}号，取款{1}，储蓄卡余额为：{2}。", DateTime.Today.Day, balance, amount);
        }
    }

    class CreditCard
    {
        private int billamount;
        private int repaymentday;

        public CreditCard(int billamount, int repaymentday)
        {
            this.billamount = billamount;
            this.repaymentday = repaymentday;
        }

        public int getbillamount() { return billamount; }

        public int getrepaymentday() { return repaymentday; }

        public void Display() { Console.WriteLine("信用卡余额为：{0}", billamount); }
    }

    class CreditCardDelegate
    {
        public int billamount;
        public int repaymentday;
        public delegate void Call(int b,int r);
        public event Call Myevent;
        public void notify()
        {
            if (DateTime.Today.Day == repaymentday && Myevent != null)
            {
                Myevent(billamount, repaymentday);
                Console.WriteLine("还款成功!");
            }
            else
                Console.WriteLine("还款失败!");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            DepositCard depositCard = new DepositCard();
            depositCard.amount = 10000;
            CreditCard creditCard1 = new CreditCard(-2000,9);
            CreditCard creditCard2 = new CreditCard(-3000,13);
            CreditCard creditCard3 = new CreditCard(-5000,5);
            depositCard.Display(); Console.WriteLine("");
            List<CreditCard> Cards = new List<CreditCard>();
            Cards.Add(creditCard1); Cards.Add(creditCard2); Cards.Add(creditCard3);

            foreach (CreditCard card in Cards)
            {
                Console.WriteLine("信用卡开始执行委托还款。。。。。。");
                //请在此处添加自己的代码
                CreditCardDelegate creditCardDelegate = new CreditCardDelegate();
                creditCardDelegate.billamount = card.getbillamount();
                creditCardDelegate.repaymentday = card.getrepaymentday();
                creditCardDelegate.Myevent += new CreditCardDelegate.Call(depositCard.Account);
                creditCardDelegate.notify();
                depositCard.Display();
                Console.WriteLine("");
            }

            //Console.WriteLine("请绑定要还款的信用卡:(输入1，2，3)");
            //int a = Console.Read();
            //CreditCardDelegate creditCardDelegate = new CreditCardDelegate();
            //switch (a)
            //{
            //    case 1:
            //        creditCardDelegate.billamount = creditCard1.getbillamount();
            //        creditCardDelegate.repaymentday = creditCard1.getrepaymentday();
            //        break;
            //    case 2:
                    
            //        creditCardDelegate.billamount = creditCard2.getbillamount();
            //        creditCardDelegate.repaymentday = creditCard2.getrepaymentday();
            //        break;
            //    case 3:
            //        creditCardDelegate.billamount = creditCard3.getbillamount();
            //        creditCardDelegate.repaymentday = creditCard3.getrepaymentday();
            //        break;
            //    default : 
            //        break;
            //}
            //creditCardDelegate.Myevent += new CreditCardDelegate.Call(depositCard.Account);
            //creditCardDelegate.notify();
            //depositCard.Display();
            //Console.ReadLine();
        }
    }
}
